package com.csweimei.rentmanagementtreasure.tenant.viewModel;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.http.entity.TabOneBean;
import com.csweimei.rentmanagementtreasure.pop.PopNotice;
import com.csweimei.rentmanagementtreasure.pop.PopNotice1;
import com.csweimei.rentmanagementtreasure.pop.PopUtils;
import com.csweimei.rentmanagementtreasure.viewModel.TitleVM;

import io.reactivex.observers.DisposableObserver;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class NoticeHouseVM extends TitleVM {
    public NoticeHouseVM(@NonNull Application application, BaseModel model) {
        super(application, model);
        setTitleText("房源信息提醒");
//        setRightIconVisible(View.VISIBLE);
//        setRightImg(R.mipmap.icon_my_set);
    }

    @Override
    protected void rightIconOnClick() {
        super.rightIconOnClick();
        PopNotice1 popNotice =   new PopNotice1(mActivity);
        PopUtils.showPop(mActivity, popNotice,false);
    }

    public ObservableList<TabOneItemVM> observableList = new ObservableArrayList<>();
    public ItemBinding<TabOneItemVM> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_tab_1_house);
    public ObservableField<Integer> showSz = new ObservableField<>(View.VISIBLE);

    public ObservableList<TabOneItem1VM> observableListht = new ObservableArrayList<>();
    public ItemBinding<TabOneItem1VM> itemBindinght = ItemBinding.of(BR.viewModel, R.layout.item_tab_1_house_1);
    public ObservableField<Integer> showHt = new ObservableField<>(View.GONE);

    public void getHouseMsg(String s){
        model.beleaselist(AppConfig.getCurMap(model))
                .compose(RxUtils.schedulersTransformer())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(this)
                .subscribe(new DisposableObserver<TabOneBean>() {
                    @Override
                    public void onNext(TabOneBean o) {
                        if (o.issucc){
                            if (s.equals("待收租")){
                                observableList.clear();
                                showSz.set(View.VISIBLE);
                                showHt.set(View.GONE);
                                if (o.getData().getBe().size() > 0){
                                    for (TabOneBean.DataDTO.BeDTO bean : o.getData().getBe()) {
                                        TabOneItemVM tabOneItemVM = new TabOneItemVM(NoticeHouseVM.this);
                                        tabOneItemVM.setData(bean);
                                        observableList.add(tabOneItemVM);
                                    }
                                }

                            }else {
                                observableListht.clear();
                                showSz.set(View.GONE);
                                showHt.set(View.VISIBLE);
                                if (o.getData().getDue().size() > 0){
                                    for (TabOneBean.DataDTO.DueDTO bean : o.getData().getDue()) {
                                        TabOneItem1VM tabOneItemVM = new TabOneItem1VM(NoticeHouseVM.this);
                                        tabOneItemVM.setData(bean);
                                        observableListht.add(tabOneItemVM);
                                    }
                                }
                            }


                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
